package com.gdziarmaga.webshop.transaction.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.gdziarmaga.webshop.book.model.Book;

@Entity
@Table(name = "Transaction_Book")
public class TransactionBook implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3554973643575129838L;
	private long transaction_book_id;
	private Book book;
	private Transaction transaction;
	private int bought_books;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "transaction_book_seq")
	@SequenceGenerator(name = "transaction_book_seq", sequenceName = "TRANSACTION_BOOK_SEQ")
	@Column(name = "transaction_book_id", precision = 20, scale = 0, unique = true)
	public long getTransaction_book_id() {
		return transaction_book_id;
	}

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "transaction_id")
	public Transaction getTransaction() {
		return transaction;
	}

	public void setTransaction(Transaction transaction) {
		this.transaction = transaction;
	}

	public void setTransaction_book_id(long transaction_book_id) {
		this.transaction_book_id = transaction_book_id;
	}

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "book_id")
	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public void setBought_books(int bought_books) {
		this.bought_books = bought_books;
	}

	@Column(name = "bought_books", nullable = true, length = 20)
	public int getBought_books() {
		return bought_books;
	}
}
